#ifndef __COMMON_H
#define __COMMON_H


#define NULL	0

//Rounding method for calculating Cycles per vector
typedef enum 
{
	FLOOR,
	CEILING,
	CLOSEST //to closest int value. 
			//i.e closest(2.4) = 2, closest(2.6) = 3, closest(2.5) = 3
}
ROUND;

#define ALPHA 0.0000002
#define ERROR_CORRECTION 1


//Effective edge
typedef enum 
{
	ACTIVE_HIGH = 1, 
	ACTIVE_LOW = 0
}
EFFECTIVE_EDGE ;

//For flags
enum {OFF, ON};

//For encoding: 
//DEPENDANT if first encoded vector is relative to the one before
//INDEPENDANT if first encoded vector is encoded as LongVector and the
//rest are relative ti him
enum {DEPENDANT, INDEPENDANT};

//Value of fast signal bits in UTG vector
enum {MASK, NOMASK};


//Maximum number of chars in name of COLUMN. Should be enough for "timestamp" (>=9) 
#define MAX_COLUMN_NAME			16

#define MAX_SIGNAL_NAME			10

#define MAX_FILE_NAME_SIZE		256

typedef struct tagSUTG_SIGNAL
{
	char szName[MAX_SIGNAL_NAME+1];
	double Phase;
} SUTG_SIGNAL, *PSUTG_SIGNAL;




//A single UTG vector (31 bit). 
typedef struct tagSVECTOR
 {
	//The vector 31 bit value, stored as a 0x number
	int iValue;
	//Number of cencor clock cycles, during which the vector is effective
	int iCycles;
	//Absolute time (actually it is relative, from trigger)
	double Absolute;
	
	
}SVECTOR, *PSVECTOR;


///////////////////////////////////////////////////////////////////
//Parameters of a loop
////////////////////////////////////////////////////////////////////

typedef struct tagSLOOP
{
	//Length of loop body
	int iLength;
	//Number of repeats
	int iLoopCount;

} SLOOP, *PSLOOP;

//For block identification
typedef enum 
{
	FLAT,
	LOOP
}LOOP_OR_FLAT;



////////////////////////////////////////////////////////////////////////////
//Block of Vectors, represents a loop or a connective flat area.
/////////////////////////////////////////////////////////////////////////

typedef struct tagSBLOCK
{
	//Indicator if this is a loop or a flat area. 2 possible values: LOOP,FLAT
	LOOP_OR_FLAT LoopOrFlat;
	//Parameters of the loop. 
	PSLOOP sLoopData; 
	
	//Borders of the block:
	//The first vector
	PSVECTOR sFirst;
	//The last vector. 
	//Notice: if this is a Loop, sLast is last Vector in loop BODY!
	//(Not last Vector in block)
	PSVECTOR sLast;

} SBLOCK, *PSBLOCK;


///////////////////////////////////////////////////////////////////////
//Line of Vectors. (Line is defined by Hsync bit)
//Notice: This struct is actually FLAT sBLOCK. It is only necessary because
//we need a Line array to look for loops.(So if SBLOCK was used there
//would be iNumOfLines obsolete sLoopData fields
//////////////////////////////////////////////////////////////////////
 
typedef struct tagSLINE
{
	PSVECTOR sFirst;
	PSVECTOR sLast;
	//LENGTH SEEMS OBSOLETE
	//int iLength;

} SLINE, *PSLINE;



//--------------------------------------------------------------------------------------------------------
//		THE OLD ENCODER_DEFS FILE
//--------------------------------------------------------------------------------------------------------

//UTG signals location in UTG vector
typedef enum
{
	V1,
	V2,
	V3,
	V4,
	V5,
	V6,
	CH1,
	CH2,
	CH3,
	CH4,
	CH5,
	VGA1,
	VGA2,
	VGA3,
	VGA4,
	VGA5,
	VGA6,
	SUB,
	PBLK,
	OB,
	DMY,
	HBLK,
	VIS,
	HIS ,
	RESERVED,
	ADCLK,
	DS2,
	R,
	HSET,
	HRESET
}
UTG_SIGNALS;


//Maximum number of lines in the loop body
#define DEFAULT_LINE_LOOP_SIZE		3

//Maximum number of bytes in the loop body
#define DEFAULT_BYTE_LOOP_SIZE		620

//Effective edge of the HSync
#define DEFAULT_EFF_EDGE		ACTIVE_LOW

#define BAD_EFF_EDGE			-800
//Length of (cencor) clock cycle (MHz) 
#define DEFAULT_CLOCK_CYCLE		24.545

//Rounding method for calculating Cycles per vector
#define DEFAULT_ROUND			CLOSEST

//Threshhold for irrelevan vectors (in us)
#define DEFAULT_THRESHHOLD		0.004

#define DEFAULT_H_TOTAL			2870
#define BAD_H_TOTAL				-800

#define DEFAULT_V_TOTAL			286	
#define BAD_V_TOTAL				-800


//Number of bits in the UTG vector 
#define VECTOR_LENGTH			30

#define DEFAULT_INI_FILE_NAME	"utg_compressor.ini"

//Minimum number of equal consequent values to conclude masking is needed
#define MASK_MINIMUM			4

//32 bit = 4 bytes in code word
#define BYTES_IN_CODE_WORD		4 


//Maximum number of nop cycles in Short Vector encoding
#define SHORT_REPEAT_COUNT		1023
//Maximum number of nop cycles in Long Vector encoding
#define LONG_REPEAT_COUNT		65535 //2^16 - 1

//-------------------------------------------------------------------------------------------------------
//	Definitions from cpp files
//-------------------------------------------------------------------------------------------------------
#define SKIP (1 << 15)
#define DONE 0
#define UPPER_TAKEN 100
#define FAIL -1
#define NEED_LONG_VECTOR -2
#define USE_LONG_REPEAT 50

#endif __COMMON_H
